from rest_framework import serializers

from apps.goods.models import SpecificationOption, SPUSpecification


class SpecificationOptionSerializer(serializers.ModelSerializer):
    '''
        规格选项表序列化器
    '''
    # 返回规格名称
    spec = serializers.StringRelatedField()
    # 返回规格id
    spec_id = serializers.IntegerField(read_only=True)
    class Meta:
        # 指定模型类
        model = SpecificationOption
        fields = '__all__'

class SPUSpecificationSerializer(serializers.ModelSerializer):
    '''
        商品规格序列化器
    '''
    spu = serializers.StringRelatedField(read_only=True)

    class Meta:
        model = SPUSpecification
        fields = '__all__'